//  -------------------- iSharePoint -------------------- //
// 
//  Company:	IT Complex, LLC
//  Project:	Smart.Common
//  File name:	IListService.cs
//  Developer:	Solomatov Igor
//  Created:	15.04.2012
// 
//  -------------------- iSharePoint -------------------- //

using System;
using System.Collections.Generic;
using System.Web.Caching;

namespace Smart.Common.Entities
{
	/// <summary>
	/// List service
	/// </summary>
	public interface IListService<TEntityType>
		where TEntityType : Entity
	{
		/// <summary>
		/// List context
		/// </summary>
		IEntityScope Ctx { get; }

		/// <summary>
		/// List name
		/// </summary>
		string ListName { get; }

		/// <summary>
		/// List Mappper
		/// </summary>
		IEntityMapper Mapper { get; }

		/// <summary>
		/// List metadata
		/// </summary>
		MetaList Meta { get; }

		/// <summary>
		/// Default entity type
		/// </summary>
		Type DefaultEntityType { get; set; }

		/// <summary>
		/// Create entity
		/// </summary>
		TEntityType CreateEntity(string entityName, IEntityList list);

		/// <summary>
		/// Create entity
		/// </summary>
		TEntityType CreateEntity(Type entityType, IEntityList list);

		/// <summary>
		/// Create entity
		/// </summary>
		TEntityType CreateEntity(IEntityList list);

		/// <summary>
		/// Fill entity default values
		/// </summary>
		/// <param name="entity">Entity to fill</param>
		/// <returns>true, if succeeded</returns>
		bool FillEntity(TEntityType entity);

		/// <summary>
		/// Load entity values using item (loads item by Entity.ID)
		/// </summary>
		/// <param name="entity">Entity to load</param>
		/// <returns>true, if succeeded</returns>
		bool LoadEntity(TEntityType entity);

		/// <summary>
		/// Load entity values using item
		/// </summary>
		/// <param name="entity">Entity to load to</param>
		/// <param name="item">Item to load from</param>
		/// <returns>true, if succeeded</returns>
		bool LoadEntity(TEntityType entity, object item);

		/// <summary>
		/// Load entity source
		/// </summary>
		object LoadEntitySource(TEntityType entity);

		/// <summary>
		/// Save entity values in item (loads item by Entity.ID)
		/// </summary>
		/// <param name="entity">Entity to save</param>
		/// <returns>true, if succeeded</returns>
		bool SaveEntity(TEntityType entity);

		/// <summary>
		/// Save entity values in item
		/// </summary>
		/// <param name="entity">Entity to save from</param>
		/// <param name="item">Item to save to</param>
		/// <returns>true, if succeeded</returns>
		bool SaveEntity(object item, TEntityType entity);

		/// <summary>
		/// Recycles entity, uses recycling by entity.ID
		/// </summary>
		/// <param name="entity">Entity to recycle</param>
		/// <returns>true, if succeeded</returns>
		bool RecycleEntity(TEntityType entity);

		/// <summary>
		/// Recycles entity, uses recycling by item
		/// </summary>
		/// <param name="entity">Entity to recycle</param>
		/// <param name="item">Item to recycle</param>
		/// <returns>true, if succeeded</returns>
		bool RecycleEntity(TEntityType entity, object item);

		/// <summary>
		/// Loads items using query
		/// </summary>
		/// <param name="query">Data source query</param>
		/// <param name="rowLimit">Row limit</param>
		/// <param name="properties">Additional query properties</param>
		/// <returns>Items</returns>
		IEntityList<TEntityType> LoadEntities(string query, int rowLimit, Dictionary<string, object> properties);

		/// <summary>
		/// Loads items using query, uses cache
		/// </summary>
		/// <param name="query">Data source query</param>
		/// <param name="rowLimit">Row limit</param>
		/// <param name="properties">Additional query properties</param>
		/// <param name="facadeName">Cache key</param>
		/// <param name="cacheUserDependent">Cache user dependent</param>
		/// <param name="cacheUrlDependent">Cache url dependent</param>
		/// <param name="cacheAbsoluteTimeout">Cache absolute timeout</param>
		/// <param name="cacheSlidingExpiration">Cache sliding expiration</param>
		/// <param name="cachePriority">Cache item priority</param>
		/// <returns>Items</returns>
		IEntityList<TEntityType> LoadEntities(string query, int rowLimit, Dictionary<string, object> properties, string facadeName, bool cacheUserDependent, bool cacheUrlDependent,
											  TimeSpan cacheAbsoluteTimeout, TimeSpan cacheSlidingExpiration, CacheItemPriority cachePriority);

		/// <summary>
		/// Detects entity name from data source item
		/// </summary>
		/// <param name="item">Item</param>
		/// <returns>Entity information</returns>
		EntityInfo DetectEntityInfo(object item);
	}
}